#pragma once
#include "machine.h"
#include "cpu/dead6309/dead6309.h"
#include "cpu/dead63701/dead63701.h"
#include "apu/ym2151/ym2151.h"
#include "apu/msm5205/msm5205.h"

class CDoubleDragonMachine:public CMachine
{
public:
	CDead6309 *MainCPU;					//main processor
	CDead63701 *SubCPU;					//sub cpu (sprite cpu)
	CDead6309 *SoundCPU;					//sound cpu
	void *ym2151;							//ym2151 data
	void *msm5205;
protected:
	u8 MainROM[0x28000];					//main rom pages
	u8 SubROM[0x10000];					//sub rom pages
	u8 SoundROM[0x10000];				//sound rom pages
	u8 CharROM[0x10000];					//character rom
	u8 SpriteROM[0x80000];				//sprite rom
	u8 TileROM[0x40000];					//tile rom
	u8 SoundDataROM[0x40000];			//sound data rom
	u8 PROM[0x400];						//prom data
	u8 RAM[0x3800];						//ram -> fgram -> sprram -> bgram
	
#define PaletteRAM	(RAM + 0x1000)
#define FGRAM			(RAM + 0x1800)
#define SPRRAM			(RAM + 0x2000)
#define BGRAM			(RAM + 0x3000)

#define MPaletteRAM	(M->RAM + 0x1000)
#define MFGRAM			(M->RAM + 0x1800)
#define MSPRRAM		(M->RAM + 0x2000)
#define MBGRAM			(M->RAM + 0x3000)

	u8 SubRAM[0x1000];					//sub cpu ram
	u8 SoundRAM[0x1000];					//sound cpu ram

	u8 VRAM[0x9800];						//vram
	u8 NVRAM[0x400];						//nvram

	u32 Palette[0x200];					//converted palette
	u8 Input1,Input2,Input3;			//input port data
	u8 Dip1,Dip2;							//dip switches
	u8 Status;								//vblank/sub cpu status
	int Scanline;							//current scanline
	u8 *ROMPtr;								//bankswitched rom
	u8 YM2151Register;
	u8 SoundLatch;
	u32 ScrollX,ScrollY;					//scroll registers
	u8 BankReg;								//bankswitch register
	
	u8 IdleADPCM[2];
	u8 EndADPCM[2];
	u8 PosADPCM[2];
protected:
	void WritePalette(u32 addr,u8 data);
public:
	CDoubleDragonMachine();
	virtual ~CDoubleDragonMachine();
	virtual int Init();
	virtual void Kill();
	virtual void Reset();
	virtual void Blit();
	virtual void Line(u32 mainc,u32 soundc,int irq);
	virtual void Frame();
	virtual void SaveState(CState *s);
	virtual void LoadState(CState *s);
	virtual void RenderScreen(u8 *dest,int pitch);
	static u8 ReadMainCPU(void *user,u32 addr);
	static void WriteMainCPU(void *user,u32 addr,u8 data);
	static u8 ReadSubCPU(void *user,u32 addr);
	static void WriteSubCPU(void *user,u32 addr,u8 data);
	static u8 ReadSoundCPU(void *user,u32 addr);
	static void WriteSoundCPU(void *user,u32 addr,u8 data);
	static void ProcessSound(void *user,void *data,int len);
	static void YM2151IRQ(void *user,int irq);
	static void msm5205irq(void *user,int n);
	int FPS(){return(57);}	//57.4
};
